<template>

  <!--

    对话框（2）：选择物料

    -->
  <el-dialog v-dialogDrag v-dialogDragWidth :title="dialog_selectOrderDetail.title"
             :visible.sync="dialog_selectOrderDetail.visible"
             width="1100px" append-to-body>
    <!-- 检索条件 -->
    <el-card class="box-card" shadow="hover" style="margin-bottom: 20px;">
      <div slot="header" class="clearfix">
        <span><b>订单基本信息</b></span>
        <el-tooltip content="显示 / 隐藏" placement="top" style="float: right; padding: 3px 0">
          <el-switch
            v-model="fold_form_order"
            active-color="#13ce66"
            inactive-color="#ff4949"
            active-value="false"
            inactive-value="true">
          </el-switch>
        </el-tooltip>
      </div>
      <div v-show="fold_form_order== 'false'">
    <el-form :model="dialog_selectOrderDetail.queryParams"
             :inline="true" v-show="dialog_selectOrderDetail.showSearch" label-width="68px">
      <!-- 订单编号 -->
      <el-form-item label="订单编号" prop="docNum">
        <el-input
          v-model="dialog_selectOrderDetail.queryParams.docNum"
          placeholder="请输入订单编号"
          clearable
          size="small"
          @keyup.enter.native="getList_orderDetails"
        />
      </el-form-item>
      <el-form-item label="客户名称" prop="custName">
        <el-input
          v-model="dialog_selectOrderDetail.queryParams.custName"
          placeholder="请输入客户名称模糊查询"
          clearable
          @keyup.enter.native="handleQuery"
          style="width: 250px"
        />
      </el-form-item>
      <el-form-item label="物料名称" prop="itemName">
        <el-input
          v-model="dialog_selectOrderDetail.queryParams.itemName"
          placeholder="请输入物料名称模糊查询"
          clearable
          @keyup.enter.native="handleQuery"
          style="width: 250px"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini"
                   @click="getList_orderDetails">搜索</el-button>
      </el-form-item>
    </el-form>
    <!-- 订单列表 -->
    <el-table v-loading="loading" :data="dialog_selectOrderDetail.oderList" row-key="itemUuid" @selection-change="handleSelectionChange">
      <el-table-column label="订单uuid" align="center" prop="orderUuid" v-if="show1" />
      <el-table-column label="物料名称" align="center" prop="itemName" width="150"/>
      <el-table-column label="订单编号" align="center" prop="docNum" width="150"/>
      <el-table-column label="客户名称" align="center" prop="custName" width="120"/>
      <el-table-column label="客户编号" align="center" prop="custNum" width="120"/>
      <el-table-column label="销售人员" align="center" prop="salesPerson" width="120"/>
      <el-table-column label="订单日期" align="center" prop="docDt" width="150">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.docDt, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="交付日期" align="center" prop="orderDeliveryDate" width="150">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.orderDeliveryDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="订单金额" align="center" prop="orderAmt" width="120"/>
      <el-table-column label="状态" align="center" prop="dicSysNormalDisable">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.dicSysNormalDisable"/>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="orderNote" width="120"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right">
        <template slot-scope="scope">
          <el-button
            type="success" plain
            size="small"
            icon="el-icon-check"
            @click="selectOrder_done(scope)"
          >选择</el-button>
        </template>
      </el-table-column>
    </el-table>
      </div>
    </el-card>

<!--        <pagination-->
<!--      v-show="dialog_selectOrderDetail.total>0"-->
<!--      :total="dialog_selectOrderDetail.total"-->
<!--      :page.sync="dialog_selectOrderDetail.queryParams.pageNum"-->
<!--      :limit.sync="dialog_selectOrderDetail.queryParams.pageSize"-->
<!--      @pagination="getList_orderDetails"-->
<!--    />-->

    <div slot="footer" class="dialog-footer">
      <el-button @click="dialog_hide_selectOrder">取 消</el-button>
    </div>

  </el-dialog>

</template>

<script>
import {listCrmOrders,listOrderDetails} from "../../../api/crm/crmOrders";

export default {
  dicts: ['sys_normal_disable'],
  props: {
    // 角色编号
    roleId: {
      type: [Number, String]
    }
  },
  data() {
    return {
      dialog_selectOrderDetail: {
        visible: false,
        showSearch: true,
        title: "请选择物料",
        total: 0,
        oderList: [],
        queryParams:{
          itemName: null,
        }
      },
      orderDetailList:[],
      fold_form_order: 'false',
      // 遮罩层
      loading: true,
      show1: false,
      // 遮罩层
      visible: false,
      // 总条数
      total: 0,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        roleId: undefined,
        userName: undefined,
        phonenumber: undefined,
        orderUuid: undefined
      },
      selectedUser: {
        id: null,
        nickName: null,
        userName: null
      }
    };
  },
  methods: {


    /** 读取列表：订单 */
    getList_orderDetails() {
      this.loading = true;
      this.dialog_selectOrderDetail.queryParams.oaDictConfirmStatus='pass'
      listCrmOrders(this.dialog_selectOrderDetail.queryParams).then(response => {
        console.log( response )
        this.dialog_selectOrderDetail.oderList = response.rows;
        this.dialog_selectOrderDetail.total = response.total;
        this.loading = false;
      });
    },

// 多选框选中数据
    handleSelectionChange(selection) {
      this.userIds = selection.map(item => item.userId);
    },

    // 完成：选择订单
    selectOrder_done(user) {
      console.log(user)
      this.dialog_selectOrderDetail.visible = false;
      this.$emit("ok", user );
    },


    // 对话框：显示 - 选择订单
    dialog_show_selectOrder() {
      this.getList_orderDetails()
      this.dialog_selectOrderDetail.visible = true;
      this.dialog_selectOrderDetail.title = "选择订单明细";
    },

    // 对话框：隐藏 - 选择物料
    dialog_hide_selectOrder() {
      this.dialog_selectOrderDetail.visible = false;
    },


    // 显示弹框
    show() {
      this.getList_orderDetails();
      this.visible = true;
    },
    clickRow(row) {
      this.$refs.table.toggleRowSelection(row);
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList_orderDetails();
    },


    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },


  }
};
</script>
